package com.pt25.base.model.security.aspect;


import com.pt25.base.exception.BizException;
import com.pt25.base.model.security.UserSession;
import com.pt25.base.res.ResCode;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * 注解顺序：
 * LoginCheckAspect（登录验证）
 * PermissionCheckAspect（权限验证）
 */
@Order(2)
@Aspect
@Component
class LoginCheckAspect extends BaseAspect{


    @Before("@annotation(com.pt25.base.model.security.aspect.LoginCheck)")
    public void check() {
        UserSession<?> userSession = securityService.getSessionData();
        if (null == userSession) {
            throw new BizException(ResCode.UN_LOGIN.getCode(), "用户未登录！");
        }
    }

}
